std.array
Pebble 0.3.1 · all symbols on this page are stable.
Polymorphic helpers over Array<T> — the native, random-access variant of a list. Unlike List<T>, Array<T> supports O(1) indexed access via at.
Use std.array.fromList to convert a List<T> once and then index into the result repeatedly.
Methods
| Function | Description |
|---|---|
length<T>(xs: Array<T>): int | Number of elements. |
at<T>(xs: Array<T>, i: int): T | Element at index i. Fails on out-of-bounds. |
fromList<T>(xs: List<T>): Array<T> | Convert a List<T> to an Array<T>. O(n). |
Examples
using { length, at, fromList } = std.array;
const xs: Array<int> = fromList([10, 20, 30]); // 3-element array
const n: int = length(xs); // 3
const v: int = at(xs, 1); // 20